package df.bean.obj.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

public class FindQueryData {
	/*
	 public static HashMap findQueryData(Connection conn, String sql) {
			HashMap<String, String> rtnData = new HashMap<String, String>();
			Statement stmt = null;
			ResultSet rs = null;
			try {
				stmt = conn.createStatement();
				rs = stmt.executeQuery(sql);
				ResultSetMetaData rsMetaData = rs.getMetaData();
				if (rs.next()) {
					for (int i = 1; i <= rsMetaData.getColumnCount(); i++) {
						String value = "";
						if (rs.getString(i) != null && !rs.getString(i).equals("")) {
							value = rs.getString(i);
							rtnData.put(rsMetaData.getColumnName(i), value);
						} else {
							rtnData.put(rsMetaData.getColumnName(i), value);
						}
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				try {
					if (rs != null) { 
						rs.close();
					}
					if (stmt != null) {
						stmt.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			return rtnData;
		}
	 */
	 /*
	 public static ArrayList listQueryData(Connection conn, String sql) {
			ArrayList<HashMap> lsQueryData = new ArrayList<HashMap>();
			Statement stmt = null;
			ResultSet rs = null;
			try {
				stmt = conn.createStatement();
				System.out.println("listQueryData >> " + sql);
				rs = stmt.executeQuery(sql);
				ResultSetMetaData rsMetaData = rs.getMetaData();
				while (rs.next()) {
					HashMap<String, String> rtnData = new HashMap<String, String>();
					for (int i = 1; i <= rsMetaData.getColumnCount(); i++) {
						String value = "";
						if (rs.getString(i) != null && !rs.getString(i).equals("")) {
							value = rs.getString(i);
							rtnData.put(rsMetaData.getColumnName(i), value);
						} else {
							rtnData.put(rsMetaData.getColumnName(i), value);
						}
					}
					lsQueryData.add(rtnData);
				}
			} catch (Exception e) {
				System.out.println("Error " + e.getMessage());
				e.printStackTrace();
			} finally {
				try {
					if (rs != null) { 
						rs.close();
					}
					if (stmt != null) {
						stmt.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			return lsQueryData;
		}
		*/
	/*
	public static ArrayList getColumnByTable(Connection conn,String table,String hopitalCode) {
		ArrayList<String> lsQueryData = new ArrayList<String>();
		Statement stmt = null;
		ResultSet rs = null;
		String columnName="";
		try {
			stmt = conn.createStatement();
			String sql = "SELECT * FROM "+ table + " WHERE HOSPITAL_CODE ='"+hopitalCode+"'"; 
			//System.out.println("listQueryData >> " + sql);
			rs = stmt.executeQuery(sql);

			ResultSetMetaData rsMetaData = rs.getMetaData();
			if(rs.next()) {
				//HashMap<String, String> rtnData = new HashMap<String, String>();
				for(int i=1;i<= rsMetaData.getColumnCount();i++){
					columnName = rsMetaData.getColumnName(i);
					lsQueryData.add(columnName);
				}
			}
		} catch (Exception e) {
			System.out.println("Error " + e.getMessage());
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) { 
					rs.close();
				}
				if (stmt != null) {
					stmt.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return lsQueryData;
	} 
	*/
}
